package com.hjw.oop;

/**
 * 银行类，定义了余额属性，存款、取钱、查看余额方法
 * @author hjwStrart
 * @create 2022-01-08 10:47
 */
public class BankAccount {
    private Integer balance;

    public BankAccount() {
        balance = 0;
    }

    public BankAccount(Integer balance) {
        this.balance = balance;
    }

    public String getBalance() {
        return balance + "￥";
    }

    /**
     * 取钱方法
     * @param amount   取得刷量
     * @return    true取钱成功 false取钱失败
     */
    public Boolean withDraw(Integer amount){

        if (amount < 0) {
            System.out.println("请输入合法范围内的金额数量！！");
            return false;
        }
        if (balance < amount){
            System.out.println("余额不足！当前余额为：" + balance + "￥");
            return false;
        }else{
            balance -= amount;
            return true;
        }
    }

    /**
     * 存钱方法
     * @param amount   存的金额
     * @return    true存钱成功  false存钱失败
     */
    public Boolean deposite(Integer amount){
        if (amount < 0){
            System.out.println("请输入合法范围内的金额数量！！");
            return false;
        }else{
            balance += amount;
            return true;
        }
    }
}
